<?php
include "../database/database.php";

class MycouponBean
{
	public $couponid;
	public $goodsid;
	public $couprice;
	public $id;
	public $coutitle;
	public $couimage;
	public $is_use;
	public $shop;
	public $shopid;
	public $isovertime;

	function __construct($couponId,$goodsId,$couPrice,$Id,$Title,$Images,$is_use,$shop,$shopid,$isovertime)
	{
		$this->couponid = $couponId;
		$this->goodsid = $goodsId;
		$this->couprice = $couPrice;
		$this->id = $Id;
		$this->coutitle = $Title;
		$this->couimage = $Images;
		$this->is_use = $is_use;
		$this->shop = $shop;
		$this->shopid = $shopid;
		$this->isovertime = $isovertime;
	}
}

$userid = $_GET['userid'];
$sql = "SELECT * FROM `mycoupon` WHERE `userid` = ${userid}  and is_delete=0";
$result = $conn->query($sql);
$MycouPon = array();
if ($result->num_rows > 0 ) {
	while ($row = $result->fetch_assoc()) {
		$cou_id = $row['couponid'];
        //优惠券信息
		$coupon_info = $conn->query("SELECT * FROM `coupon` WHERE `couponid` = $cou_id")->fetch_assoc();
		$shop=0;
        //获取该优惠券的商户名
		if($shopid!=0){
           $sql2="select * from shop where shopid=".$coupon_info[couponid];
			$result2=$conn->query($sql2);
			$row2 = $result2->fetch_assoc();
			if($row2){
			   $shop=$row2[name];
			 }
		}
		$isovertime=0;
         //是否过期
         if(date('Y-m-d') > date($coupon_info[enddate])){
              $isovertime=1;
         }
		
		$MycouPon[] = new MycouponBean($row['couponid'],$row['goodsid'],$row['price'],$row['id'],$coupon_info['title'],$coupon_info['images'],$row['is_use'],$shop,$coupon_info[shopid],$isovertime);
		
	}
}

$conn->close();

echo json_encode($MycouPon);
?>